﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.ServiceLocation;

namespace Churchtoolkit.Utils.MVP
{
    public class Page<T> : System.Web.UI.Page  where T : Presenter
    {
        private T _presenter;
        protected T Presenter
        {
            get
            {
                if (_presenter == null)
                {
                    _presenter = ServiceLocator.Current.GetInstance<T>();
                    _presenter.InternalView = this;
                }
                return _presenter;
            }
        }
    }

    public class MasterPage<T> : System.Web.UI.MasterPage where T : Presenter
    {
        private T _presenter;
        protected T Presenter
        {
            get
            {
                if (_presenter == null)
                {
                    _presenter = ServiceLocator.Current.GetInstance<T>();
                    _presenter.InternalView = this;
                }
                return _presenter;
            }
        }
    }

    public class UserControl<T> : System.Web.UI.UserControl where T : Presenter
    {
        private T _presenter;
        protected T Presenter
        {
            get
            {
                if (_presenter == null)
                {
                    _presenter = ServiceLocator.Current.GetInstance<T>();
                    _presenter.InternalView = this;
                }
                return _presenter;
            }
        }
    }
}
